package com.gupao.javavip.spring.annotation;

import com.gupao.javavip.spring.logger.persistence.DbLoggerPersistenceImpl;
import com.gupao.javavip.spring.logger.persistence.FileLoggerPersistenceImpl;
import com.gupao.javavip.spring.logger.persistence.LoggerPersistenceType;
import org.springframework.context.annotation.ImportSelector;
import org.springframework.core.type.AnnotationMetadata;

import java.util.Map;

/**
 * @author King
 * @Classname LoggerPersistenceSelector
 * @Description
 * @Date 2020/5/7 9:59
 */
public class LoggerPersistenceSelector implements ImportSelector {

    @Override
    public String[] selectImports(AnnotationMetadata importingClassMetadata) {
        Map<String, Object> annotationAttrs = importingClassMetadata.getAnnotationAttributes(EnableLoggerPersistence.class.getName());
        LoggerPersistenceType type = (LoggerPersistenceType) annotationAttrs.get("type");

        switch (type) {
            case DB:
                return new String[]{DbLoggerPersistenceImpl.class.getName()};
            default:
                return new String[]{FileLoggerPersistenceImpl.class.getName()};
        }

    }
}
